/**************
 * File Name: DBBase.h
 * Author: jade@design1online.com
 * Purpose: header file for DBBase.cpp class
 **************/
#ifndef DBBASE_H_
#define DBBASE_H_

#include "mysql/mysql.h"
#include <string>
#include <cstdlib>
/**************
 * Database Error Definitions
 **************/
#define SUCCESS 200
#define ERR201 201
#define ERR202 202
#define ERR203 203
#define MAX_QUERY_LEN 500
using namespace std;
class DBBase
{
    public:
        //class constructor
        DBBase(); 

        //connection & disconnect
        int       openConnection(const char *host,const char *db, const char *user,const char *pass); //connect to the DBBase
        bool      disconnect(); //disconnect from the DBBase

        //querying
        MYSQL_RES *query(const char* query); //return result set
        char      *stringQuery(char *query); //return string
        int       intQuery(char *query); //return an integer
        bool      boolQuery(char *query); //return a boolean
        bool      updateQuery(string query); //updates, returns true if update went through
        void      reportError(string& query);

        //free the query results
        bool free();

    private:
        MYSQL *sock;
        MYSQL_RES *result;
        MYSQL_ROW row;
        MYSQL_FIELD *field;
        char *qbuf[MAX_QUERY_LEN];
};

const char *dberror(int errorcode); //return a string for this error message

#endif
